package com.example.servlet;


import com.example.pojo.Ent;
import com.example.service.EntService;
import com.example.service.Impl.EntServiceImpl;
import com.example.util.BackContent;
import com.example.util.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//WebServlet注解
@WebServlet("/ent")
public class EntServlet extends BaseServlet {

    EntService entService=new EntServiceImpl();

    /**
     * 删除相关信息EntDel
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    public BackContent EntDel(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        String s = entService.EntDel(id);
        BackContent backContent = new BackContent();
        backContent.setZt(200);
        backContent.setZtContent("删除成功");
        return backContent;
    }

    /**
     * 用户新增相关的servlet方法EntAdd
     * @param request
     * @param response
     * @return
     */
    public String EntAdd(HttpServletRequest request,HttpServletResponse response){
        String name = request.getParameter("name");
        Integer workingLife = Integer.valueOf(request.getParameter("workingLife"));
//        String workExperience = request.getParameter("workExperience");
        String personalProfile = request.getParameter("personalProfile");
//        Integer departmentId = Integer.valueOf(request.getParameter("departmentId"));
        String graduateSchool = request.getParameter("graduateSchool");
        Ent ent = new Ent();
        ent.setName(name);ent.setWorkingLife(workingLife);
//        ent.setWorkExperience(workExperience);
        ent.setPersonalProfile(personalProfile);
//        ent.setDepartmentId(departmentId);
        ent.setGraduateSchool(graduateSchool);
        String s = entService.EntAdd(ent);
        BackContent backContent = new BackContent();
        if (s.equals("新增成功")){
            backContent.setZt(200);
            backContent.setZtContent("新增成功");
        }else {
            backContent.setZt(500);
            backContent.setZtContent("新增失败");
        }
        List<Ent> ents = entService.EntAll();
        request.setAttribute("entAll",ents);
        return "homePage";
    }


    /**
     * 修改信息的servlet方法EntEdit
     * @param request
     * @param response
     * @return
     */
    public BackContent EntEdit(HttpServletRequest request,HttpServletResponse response){
        Integer id =Integer.valueOf(request.getParameter("id"));
        String name = request.getParameter("name1");
        Integer workingLife = Integer.valueOf(request.getParameter("workingLife1"));
//        String workExperience = request.getParameter("workExperience");
        String personalProfile = request.getParameter("personalProfile");
//        Integer departmentId = Integer.valueOf(request.getParameter("departmentId"));
        String graduateSchool = request.getParameter("graduateSchool");
        Ent ent = new Ent();
        ent.setId(id);ent.setName(name);ent.setWorkingLife(workingLife);
//        ent.setWorkExperience(workExperience);
        ent.setPersonalProfile(personalProfile);
//        ent.setDepartmentId(departmentId);
        ent.setGraduateSchool(graduateSchool);
        String s = entService.EntEdit(ent);
        BackContent backContent = new BackContent();
        if (s.equals("修改成功")){
            backContent.setZt(200);
            backContent.setZtContent("修改成功");
        }else {
            backContent.setZt(500);
            backContent.setZtContent("修改失败");
        }
        return backContent;
    }

    @Override
    public Class<?> getServletClass() {
        return EntServlet.class;
    }
}
